<?php require_once('Connections/adminConn.php'); ?><?php
if (!isset($_SESSION)) {
  session_start();
}
$MM_authorizedUsers = "admin";
$MM_donotCheckaccess = "false";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && false) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "index.php?site=adminPage";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0) 
  $MM_referrer .= "?" . $QUERY_STRING;
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE `user` SET password=%s WHERE username=%s",
                       GetSQLValueString($_POST['password'], "text"),
                       GetSQLValueString($_POST['username'], "text"));

  mysql_select_db($database_adminConn, $adminConn);
  $Result1 = mysql_query($updateSQL, $adminConn) or die(mysql_error());

  $updateGoTo = "usersAdmin2.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form2")) {
  $updateSQL = sprintf("UPDATE game_summary SET game_key=%s, rating=%s, wins=%s, loses=%s, draws=%s, streak=%s WHERE username=%s",
                       GetSQLValueString($_POST['game_key'], "text"),
                       GetSQLValueString($_POST['rating'], "int"),
                       GetSQLValueString($_POST['wins'], "int"),
                       GetSQLValueString($_POST['loses'], "int"),
                       GetSQLValueString($_POST['draws'], "int"),
                       GetSQLValueString($_POST['streak'], "int"),
                       GetSQLValueString($_POST['username'], "text"));

  mysql_select_db($database_adminConn, $adminConn);
  $Result1 = mysql_query($updateSQL, $adminConn) or die(mysql_error());

  $updateGoTo = "usersAdmin2.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

$colname_usersAdnPasswords = "-1";
if (isset($_GET['username'])) {
  $colname_usersAdnPasswords = $_GET['username'];
}
mysql_select_db($database_adminConn, $adminConn);
$query_usersAdnPasswords = sprintf("SELECT * FROM `user` WHERE username = %s", GetSQLValueString($colname_usersAdnPasswords, "text"));
$usersAdnPasswords = mysql_query($query_usersAdnPasswords, $adminConn) or die(mysql_error());
$row_usersAdnPasswords = mysql_fetch_assoc($usersAdnPasswords);
$totalRows_usersAdnPasswords = mysql_num_rows($usersAdnPasswords);

$colname_userRecords = "-1";
if (isset($_GET['username'])) {
  $colname_userRecords = $_GET['username'];
}
mysql_select_db($database_adminConn, $adminConn);
$query_userRecords = sprintf("SELECT * FROM game_summary WHERE username = %s and game_key = 'reversi'", GetSQLValueString($colname_userRecords, "text"));
$userRecords = mysql_query($query_userRecords, $adminConn) or die(mysql_error());
$row_userRecords = mysql_fetch_assoc($userRecords);
$totalRows_userRecords = mysql_num_rows($userRecords);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
Design by Free CSS Templates
http://www.freecsstemplates.org
Released for free under a Creative Commons Attribution 2.5 License

Name       : FronzenAge
Description: A two-column, fixed-width template suitable for business sites and blogs.
Version    : 1.0
Released   : 20071108

-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>MWLReversi</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
<!--[if IE]>
<style type="text/css">
#sidebar #calendar {
	background-position: 0px 20px;
}
</style>
<![endif]-->
</head>
<body>
<div id="logo">
	<h1><a href="#">MWLReversi</a></h1>
	<h2></a>Gra Planszowa Online</h2>
</div>
<div id="menu">
	<ul>
		<li class="first"><a href="index.php?site=mainPage" accesskey="1" title="">Strona Główna</a></li>
		<li><a href="index.php?site=userPage" accesskey="2" title="">Użytkownik</a></li>
		<li><a href="index.php?site=adminPage" accesskey="3" title="">Administrator</a></li>
		<li><a href="index.php?site=playGamePage" accesskey="4" title="">Zagraj</a></li>
	</ul>
<?php 
$site;
if (is_null($_GET["site"]) == false)
$site= $_GET["site"];
else $site = "mainPage";
?>

	<div id="search">
		<!-- pole do wyszukiwania wyrzucic -->
	</div>
</div>
<hr />
<div id="banner"><img src="images/img04.jpg" alt="" width="960" height="147" /></div>
<!-- start page -->
<div id="page">
	<!-- start content -->
<form action="<?php echo $editFormAction; ?>" method="post" id="form1">
      <table>
        <tr valign="baseline">
          <td align="right">Nazwa Urzytkownika</td>
          <td><?php echo $row_usersAdnPasswords['username']; ?></td>
        </tr>
        <tr valign="baseline">
          <td align="right">Haslo</td>
          <td><input type="text" name="password" value="<?php echo htmlentities($row_usersAdnPasswords['password'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
        </tr>
        <tr valign="baseline">
          <td align="right">&nbsp;</td>
          <td><input type="submit" value="Update record" /></td>
        </tr>
      </table>
      <input type="hidden" name="MM_update" value="form1" />
      <input type="hidden" name="username" value="<?php echo $row_usersAdnPasswords['username']; ?>" />
    </form>
    
    <p>&nbsp;</p>
    
    <form action="<?php echo $editFormAction; ?>" method="post" id="form2">
      <table>
        <tr valign="baseline">
          <td align="right">Nazwa Urzytkownika</td>
          <td><?php echo $row_userRecords['username']; ?></td>
        </tr>
        <tr valign="baseline">
          <td align="right">Punkty</td>
          <td><input type="text" name="rating" value="<?php echo htmlentities($row_userRecords['rating'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
        </tr>
        <tr valign="baseline">
          <td align="right">Wygrane</td>
          <td><input type="text" name="wins" value="<?php echo htmlentities($row_userRecords['wins'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
        </tr>
        <tr valign="baseline">
          <td align="right">Przegrane</td>
          <td><input type="text" name="loses" value="<?php echo htmlentities($row_userRecords['loses'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
        </tr>
        <tr valign="baseline">
          <td align="right">Remisy</td>
          <td><input type="text" name="draws" value="<?php echo htmlentities($row_userRecords['draws'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
        </tr>
        <tr valign="baseline">
          <td align="right">Ucieczki</td>
          <td><input type="text" name="streak" value="<?php echo htmlentities($row_userRecords['streak'], ENT_COMPAT, 'utf-8'); ?>" size="32" /></td>
        </tr>
        <tr valign="baseline">
          <td align="right">&nbsp;</td>
          <td><input type="submit" value="Update record" /></td>
        </tr>
      </table>
      <input type="hidden" name="game_key" value="<?php echo htmlentities($row_userRecords['game_key'], ENT_COMPAT, 'utf-8'); ?>" />
      <input type="hidden" name="MM_update" value="form2" />
      <input type="hidden" name="username" value="<?php echo $row_userRecords['username']; ?>" />
    </form>
    
    <p>&nbsp;</p>
<!-- end content -->
	<!-- start sidebar -->
	<div id="sidebar">
    <?php
	include "adminMenu.php";
	?>
<!-- boczny panel do wywalenia!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->		
	<!-- end sidebar -->
</div>
<!-- end page -->
<div id="footer">
	<p class="legal">Copyright (c) 2008 MWLReversi. All rights reserved.</p>
	<p class="credit">Designed by <a href="http://www.nodethirtythree.com/">NodeThirtyThree</a> + <a href="http://www.freecsstemplates.org/">Free CSS Templates</a></p>
</div>
</body>
</html>
<?php
mysql_free_result($usersAdnPasswords);

mysql_free_result($userRecords);
?>
